Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdf -> usd: Materials #831

Merged
merged 38 commits into from
Mar 4, 2022
Merged

sdf -> usd: Materials #831

merged 38 commits into from
Mar 4, 2022

Conversation

ahcorde
Copy link
Collaborator

@ahcorde ahcorde commented Jan 26, 2022

Signed-off-by: ahcorde [email protected]

🎉 New feature

Summary

Suppor for materials in the sdf to usd converter:

  • Conversor between sdf::Material and ignition::common::Materials
    • Added tests
  • Added material parser
    • Added tests

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@ahcorde ahcorde self-assigned this Jan 26, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2022

Codecov Report

Merging #831 (3095a50) into sdf12 (c7fd82d) will decrease coverage by 0.86%.
The diff coverage is 61.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##            sdf12     #831      +/-   ##
==========================================
- Coverage   89.34%   88.48%   -0.87%     
==========================================
  Files          90       92       +2     
  Lines       13744    14190     +446     
==========================================
+ Hits        12280    12556     +276     
- Misses       1464     1634     +170     
Impacted Files Coverage Δ
usd/src/cmd/sdf2usd.cc 29.20% <4.47%> (-36.02%) ⬇️
usd/src/sdf_parser/Visual.cc 46.00% <40.00%> (-4.00%) ⬇️
usd/src/sdf_parser/Geometry.cc 63.53% <51.72%> (-1.39%) ⬇️
usd/src/sdf_parser/Material.cc 74.10% <74.10%> (ø)
usd/src/Conversions.cc 81.01% <81.01%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7fd82d...3095a50. Read the comment docs.

Signed-off-by: Ashton Larkin <[email protected]>
Copy link

@koonpeng koonpeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put the link to the docs containing the TfTokens used?

Copy link
Contributor

@adlarkin adlarkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few updates in 7130c1f, but I have not reviewed all of the files in this PR yet. Here are some questions that I have so far.

usd/src/Conversions.cc Outdated Show resolved Hide resolved
usd/src/Conversions_TEST.cc Outdated Show resolved Hide resolved
usd/src/sdf_parser/Material_Sdf2Usd_TEST.cc Show resolved Hide resolved
Signed-off-by: ahcorde <[email protected]>
usd/src/sdf_parser/Geometry.cc Show resolved Hide resolved
usd/src/cmd/sdf2usd.cc Outdated Show resolved Hide resolved
usd/src/cmd/sdf2usd.cc Outdated Show resolved Hide resolved
usd/src/cmd/sdf2usd.cc Show resolved Hide resolved
Signed-off-by: Ashton Larkin <[email protected]>
usd/src/sdf_parser/Material.cc Outdated Show resolved Hide resolved
usd/include/sdf/usd/sdf_parser/Material.hh Outdated Show resolved Hide resolved
Signed-off-by: ahcorde <[email protected]>
@ahcorde ahcorde requested a review from adlarkin March 1, 2022 14:05
usd/include/sdf/usd/sdf_parser/Material.hh Outdated Show resolved Hide resolved
usd/src/sdf_parser/Geometry.cc Show resolved Hide resolved
usd/src/sdf_parser/Geometry.cc Outdated Show resolved Hide resolved
usd/include/sdf/usd/Conversions.hh Outdated Show resolved Hide resolved
/// \param[in] _in SDF material.
/// \return Ignition Common Material.
IGNITION_SDFORMAT_USD_VISIBLE
std::shared_ptr<ignition::common::Material> convert(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why return a shared_ptr here? Is it important that the resulting Material be allocated on the heap? we return an sdf::Material object from the other function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really sure about how to deal with this, because I can't return a ignition::common::Material because is a non-copyable class (it has a unique_ptr inside). I decided touse the same type in both methods.

@scpeters what do you think is right type ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, that's reasonable. I'll open an issue in ign-common suggesting that we improve the Material class to make it copyable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it has a move ctor, then you should be might be able to return ignition::common::Material and the compiler will use copy elision to construct the object at the call location.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't have a move ctor https://github.com/ignitionrobotics/ign-common/blob/ign-common4/graphics/include/ignition/common/Material.hh#L90-L97

@azeey, does it make sense to include it ? or can we keep the shared_ptr ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, since it has a user declared destructor, the compiler will not generate a move ctor. Simply removing the destructor would fix this, but I think that will break ABI. So, returning a smart pointer seems to be our best bet, but if we have to do that, my preference would be to use a unique_ptr unless there is a particular reason to use a shared_ptr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SubMesh::MaterialByIndex returns a shared_ptr which mean we need to convert this shared_ptr to unique_ptr to finally get the sdf::Material. I will bet for the shared_ptrto simplify things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an idea for getting around the std::shared_ptr issue - see 3095a50. If you guys think this isn't a good solution, feel free to revert this commit.

Signed-off-by: ahcorde <[email protected]>
@ahcorde ahcorde requested a review from scpeters March 2, 2022 09:07
Signed-off-by: ahcorde <[email protected]>
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't go deeply into all the details here, but the API seems ok

Copy link
Contributor

@adlarkin adlarkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some changes in cdc0257 and 8b97a1c. I also tried to address the std::shared_ptr issue discussed in #831 (comment) with 3095a50, so once someone looks at my workaround, I think this is good to go.

@ahcorde ahcorde merged commit 9641718 into sdf12 Mar 4, 2022
@ahcorde ahcorde deleted the ahcorde/sdf_to_usd_materials branch March 4, 2022 08:49
@ahcorde ahcorde mentioned this pull request Mar 4, 2022
8 tasks
@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-04-13-fortress-edifice/1367/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants